﻿using System;
using System.Collections.Generic;
using Honeycomb.Core;

namespace Honeycomb.Sample.Prime
{
    [Serializable]
    public class PrimeTask : TaskBase
    {
        int Start { get; set; }
        int Stop { get; set; }

        public PrimeTask(int start, int stop)
        {
            Start = start;
            Stop = stop;
        }

        public override object Execute()
        {
            List<int> primes = new List<int>();
            for (int i = Start; i < Stop; i++)
                if (IsPrime(i))
                    primes.Add(i);

            return primes;
        }

        private static bool IsPrime(int number)
        {
            for (int i = 2; i < number; i++)
                if (number % i == 0)
                    return false;

            return true;
        }
    }
}